<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

use think\facade\Route;

Route::pattern('id', '\d+');

Route::get('/', function(){
    return welcome();
});
/**
 * 后台管理模块
 */
Route::group('admin', function(){
    // 登录模块
    Route::group('login', function(){
        Route::get('/', 'admin/Login/login');
        Route::post('input', 'admin/Login/input');
        Route::get('logout', 'admin/Login/logout');
    });
    //rbac
    Route::group('rbac', function(){
        Route::get('table', function(){
            (new \gmars\rbac\Rbac())->createTable();
        });
    });
    Route::group('', function(){
        //首页
        Route::get('/', 'admin/Index/index');
        Route::get('welcome', 'admin/Index/welcome');
        Route::get('icon', 'admin/Index/getIcon');
        //公共操作
        Route::controller('common', 'admin/Common');
        // 管理员模块
        Route::group('admin', function(){
            Route::get('admin/skin/:skin','admin/admin.Administrator/skin')->validate('app\admin\validate\Admin', 'skin');
            Route::get('admin/status/:id', 'admin/admin.Administrator/status')->model('\app\admin\model\admin\Admin');
            Route::get('admin/only', 'admin/admin.Administrator/only');
            Route::delete('admin/destory', 'admin/admin.Administrator/destory');
            Route::resource('admin', 'admin/admin.Administrator')->model('\app\admin\model\admin\Admin');
            Route::get('permission/status/:id', 'admin/admin.Permission/status')->model('\app\admin\model\admin\Permission');
            Route::get('permission/auto', 'admin/admin.Permission/auto');
            Route::delete('permission/destory', 'admin/admin.Permission/destory');
            Route::resource('permission', 'admin/admin.Permission');
            Route::get('permissionCategory/status/:id', 'admin/admin.PermissionCategory/status')->model('\app\admin\model\admin\PermissionCategory');
            Route::get('permissionCategory/only', 'admin/admin.PermissionCategory/only');
            Route::delete('permissionCategory/destory', 'admin/admin.PermissionCategory/destory');
            Route::resource('permissionCategory', 'admin/admin.PermissionCategory');
            Route::get('roles/status/:id', 'admin/admin.Roles/status')->model('\app\admin\model\admin\Role');
            Route::delete('roles/destory', 'admin/admin.Roles/destory');
            Route::resource('roles', 'admin/admin.Roles');
            Route::get('menus/status/:id', 'admin/admin.Menus/status')->model('\app\admin\model\admin\Menus');
            Route::get('menus/only', 'admin/admin.Menus/only');
            Route::delete('menus/destory', 'admin/admin.Menus/destory');
            Route::resource('menus', 'admin/admin.Menus')->model('\app\admin\model\admin\Menus');
        });
        //用户模块
        Route::group('user', function(){
            Route::get('info/status/:id', 'admin/user.Info/status')->model('\app\admin\model\user\UserNumber');
            Route::get('info/only', 'admin/user.Info/only');
            Route::resource('info', 'admin/user.Info')->model('\app\admin\model\user\UserNumber');
        });
        //系统模块
        Route::group('system', function(){
            Route::resource('setting', 'admin/system.System')->model('\app\admin\model\system\System');
        });
        // 菜品管理
        Route::group('foods', function(){
            Route::get('category/status/:id', 'FoodCategory/status')->model('\app\admin\model\foods\FoodCategory');
            Route::delete('category/destory', 'FoodCategory/destory');
            Route::resource('category', 'FoodCategory')->model('\app\admin\model\foods\FoodCategory');
            Route::get('food/status/:id', 'Foods/status')->model('\app\admin\model\foods\Foods');
            Route::delete('food/destory', 'Foods/destory');
            Route::resource('food', 'Foods')->model('\app\admin\model\foods\Foods');
        })->prefix('admin/foods.');
        // 工具模块
        Route::group('tools', function(){
            Route::get('accountCategory/status/:id', 'AccountCategory/status')->model('\app\admin\model\tools\AccountCategory');
            Route::delete('accountCategory/destory', 'AccountCategory/destory');
            Route::resource('accountCategory', 'AccountCategory')->model('\app\admin\model\tools\AccountCategory');
            Route::delete('account/destory', 'Account/destory');
            Route::resource('account', 'Account')->model('\app\admin\model\tools\Account');
        })->prefix('admin/tools.');
        // 订单管理
        Route::group('order', function(){
            Route::group('handle', function(){
                Route::get('list', 'handle');
                Route::delete('batchComplete', 'batchComplete');
                Route::delete('complete/:id', 'complete');
                Route::delete('batchCancel', 'batchCancel');
                Route::delete('cancel/:id', 'cancel');
                Route::get('count', 'count');
            })->prefix('admin/order.Order/');
            Route::resource('order', 'admin/order.Order')->model('\app\admin\model\order\Order');
        });
    })->middleware([
        \app\http\middleware\IfLogin::class,
        \app\http\middleware\AuthUpdate::class
    ]);
});

// api接口
Route::group('api', function(){
    Route::group('v1', function(){
        Route::group('user', function(){
            Route::get('oauth2', 'OAuth2/login');
            Route::group('', function(){
                Route::post('addInfo', 'OAuth2/addInfo');
                Route::get('address/default/:id', 'Address/defaultAddress');
                Route::resource('address', 'Address')->model(\app\api\model\user\Address::class);
            })->middleware([
                \app\http\middleware\CheckToken::class
            ]);
        })->prefix('api/user.');
        Route::group('', function(){
            //菜品模块
            Route::group('foods', function(){
                Route::get('lists', 'Foods/lists');
            })->prefix('api/foods.');
            // 订单模块
            Route::group('order', function(){
                Route::group('shopping', function(){
                    Route::post('add', 'ShoppingCart/add')->validate(\app\api\validate\order\ShoppingCart::class, 'add');
                    Route::get('clean', 'ShoppingCart/clean');
                    Route::get('cart', 'ShoppingCart/cart');
                    Route::delete('reduce/:id', 'ShoppingCart/reduce');
                });
                Route::group('order', function(){
                    Route::get('confirm', 'Order/confirm');
                    Route::post('set', 'Order/setOrder');
                    Route::get('lists', 'Order/lists');
                    Route::get('read/:id', 'Order/read');
                    Route::get('cancel/:id', 'Order/cancel');
                });
            })->prefix('api/order.');
            // 系统模块
            Route::group('system', function(){
                Route::get('rest', 'System/rest');
            })->prefix('api/system.');
        })->middleware([
            \app\http\middleware\CheckToken::class
        ]);
    });
});

/**
 * 命令行相关
 */
Route::group('console', function(){
    Route::get('call/:password', function($password){
        if ( $password !== 'administrator' ) return notFound();
        $callRes[] = \think\Console::call('clear')->fetch();
        $callRes[] = \think\Console::call('optimize:schema')->fetch();
        $callRes[] = \think\Console::call('optimize:config')->fetch();
        $callRes[] = \think\Console::call('optimize:route')->fetch();
        return json($callRes);
    });
    Route::get('clear/:password',function($password){
        if ( $password !== 'administrator' ) return notFound();
        return \think\Console::call('clear')->fetch();
    });
});

return [

];
